package com.cskaoyan.service.impl;

import com.cskaoyan.mapper.CommentMapper;
import com.cskaoyan.model.Comment;
import com.cskaoyan.model.Goods;
import com.cskaoyan.model.bo.BaseParamBO;
import com.cskaoyan.model.vo.CommentDataVO;
import com.cskaoyan.model.vo.GoodsDataVO;
import com.cskaoyan.service.CommentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @program: mall38
 * @description:
 * @author: Wang
 * @create: 2022-05-06 23:35
 **/
public class CommentServiceImpl implements CommentService {

    @Autowired
    CommentMapper commentMapper;

    @Override
    public CommentDataVO query(Integer userId, BaseParamBO param) {

        Integer page = param.getPage();//页码
        Integer limit = param.getLimit();//数据量
        String sort = param.getSort();//排序列
        String order = param.getOrder();//desc\asc
        //分页插件 PageHelper，辅助我们做分页以及分页信息的获得
        PageHelper.startPage(page, limit);
        //执行查询过程中拼接分页信息
        List<Comment> list = commentMapper.select(sort,order,userId);

        //total、pages、list
        //通过PageHelper帮我们来获得一些和分页相关的信息PageInfo
        //使用其有参构造方法 → 形参写来源于数据库的list
        PageInfo<Comment> pageInfo = new PageInfo<>(list);
        long total = pageInfo.getTotal();
        int pages = pageInfo.getPages();
        return CommentDataVO.data(total,pages,limit,page,list);
    }
}
